package com.vay.de.dang.online.util;

import android.content.Context;
import android.content.SharedPreferences;
import android.preference.PreferenceManager;

public final class VnPfReader {

    private static VnPfReader _instance;
    private SharedPreferences mPf;
    private SharedPreferences.Editor mEditor;

    private VnPfReader(Context context) {
        mPf = PreferenceManager.getDefaultSharedPreferences(context);
        mEditor = mPf.edit();
    }

    public static void init(Context context) {
        if (_instance == null) {
            _instance = new VnPfReader(context);
        }
    }

    public static VnPfReader instance() {
        return _instance;
    }

    public void putString(String key, String value) {
        mEditor.putString(key, value).commit();
    }

    public String readString(String key) {
        return mPf.getString(key, null);
    }

    public int readInt(String key) {
        return mPf.getInt(key, -1);
    }

    public void putInt(String key, int value) {
        mEditor.putInt(key, value).commit();
    }

    public void putBoolean(String key, boolean value) {
        mEditor.putBoolean(key, value).commit();
    }

    public boolean readBoolean(String key) {
        return mPf.getBoolean(key, false);
    }
}
